﻿@model Tuple<List<deviceManage.Models.DocumentType>,int?>
@{
    ViewData["Title"] = "文档管理";
}
 
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto search" lay-filter="searchForm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">文档名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">类型</label>
                            <div class="layui-input-inline">
                                <select name="typeId">
                                    <option></option>
                                    @foreach(var type in @Model.Item1)
                                    {
                                    <option value="@type.Id">@type.Name</option>
                                    }
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-list" lay-submit="" id="searchBtn" lay-filter="search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                            </button>
                            @if (1 != Model.Item2)
                            {
                                <button onclick="add()" class="layui-btn">上传文档</button>
                            }
                        </div>
                    </div>
                </div>

                <div class="layui-card-body">
                    
                    <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
                </div>
            </div>
        </div>
 


<script>

 
    form.render("select","searchForm");
    //监听搜索
    form.on('submit(search)', function (data) {
        var field = data.field;
        //执行重载
        table.reload('LAY-app-content-list', {
            where: field
        });
    });


    //加载table
    var tableObj = table.render({
        elem: '#LAY-app-content-list'
        , url: '/doc/DocManageList'
        , page: true
        , height: 'full-110'
        , cols: [[
            { field: 'title', title: '文档名称', minWidth: 250, templet: '<div>{{ d.name}}</div>' }
            , { field: 'sortOrder', title: '类型', width: 200, templet: '<div>{{ d.type.name}}</div>' }
            , { field: 'sortOrder', title: '上传时间', width: 120, templet: '<div>{{ getDate(d.uploadTime)}}</div>' }
            , {
                field: 'opr', title: '操作',width:150,
                templet: '<div class="layui-table-cell laytable-cell-11-0-8"> <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="deleteDoc(\'{{ d.id }}\')"><i class="layui-icon layui-icon-delete"></i>删除</a> </div>'
            }

            ]]
            , skin: 'line'
        });

    //上传文档
    var editWin = null;
    function add() {
        $.get("/doc/DocBatchUpload", function (str) {
            editWin = layer.open({
                type: 1                
                ,title:'上传文档'
                ,content: str
                ,area:["700px","500px"]
            });
        });
    }



    function deleteDoc(id) {
        layer.confirm("确定要删除吗？", {title:'删除'}, function (index) {
            layer.close(index);
            $.post("/doc/Delete?id=" + id, function (d) {
                layer.msg(d.msg);
                if (d.code == 1) {
                    tableObj.reload();
                }
            });
        });
    }

    $(document).on('keydown', function (e) {
        if (e.keyCode == 13) {
            $("#searchBtn").click();
        }
    })
</script>

